package com.lashou.chunshen.lashoutuangou.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lashou.chunshen.lashoutuangou.R;
import com.lashou.chunshen.lashoutuangou.bean.BaseBean;
import com.lashou.chunshen.lashoutuangou.bean.HomeCategory;

/**
 * Created by Administrator on 2016/8/30.
 */
public class HomeFenleiAdapter extends PagerAdapter {

    private int mSize;
    private Activity mActivity;
    private HomeCategory homeCategory;
    public HomeFenleiAdapter(Activity activity) {
        mActivity = activity;
        mSize = 2;
    }

    public HomeFenleiAdapter(int count) {
        mSize = count;
    }

    @Override public int getCount() {
        return mSize;
    }

    @Override public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override public void destroyItem(ViewGroup view, int position, Object object) {
        view.removeView((View) object);
    }

    @Override public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(mActivity.getApplicationContext()).inflate(R.layout.home_category, container, false);
        ImageView imageView = (ImageView)view.findViewById(R.id.iv_home_category);
        TextView textView = (TextView)view.findViewById(R.id.tv_home_category);
        textView.setText(homeCategory.getResult());
//        imageView.setImageResource(ResIds[position]);
//        Bitmap image = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//        Bitmap newimage = getRoundCornerImage(image,50);
//        ImageView imageView2 = new ImageView(view.getContext());
//        imageView2.setImageBitmap(newimage);
//        container.addView(view);
        return view;
    }
    //增加一个item
    public void addItem() {
        mSize++;
        notifyDataSetChanged();
    }
    //删除一个item
    public void removeItem() {
        mSize--;
        mSize = mSize < 0 ? 0 : mSize;
        notifyDataSetChanged();
    }
    //设置数据
    public void setDatas(HomeCategory homeCategory){
        this.homeCategory = homeCategory;
        notifyDataSetChanged();
    }


}